package com.tinyseed.emcp.api.app.config;

import com.tinyseed.hmxx.admin.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Slf4j
public class SpringSecurityAuditorAware implements AuditorAware<String> {

    @Override
    public Optional<String> getCurrentAuditor() {
        String username = SecurityUtils.getusernameUnerror();
        if (username != null){
            return Optional.of(username);
        } else {
            return Optional.empty();
        }
    }
}
